# path information
PROJECT_ROOT=$(shell pwd)
BUILD_ROOT=$(PROJECT_ROOT)/build

# os commands
SED=sed
MAKE=make
MVN=mvn

# targets
BACKEND=backend
POWER_AGENT=power_agent
POWER_MASTER=powermaster
POWER_MARKET=market
POWER_MARKET_ADAPTER=marketadapter
HTTP_GATEWAY=http-gateway
SCRIPTS=scripts
AUTOMATION=testing
AI=ai
I6000=i6000
SVC_ISCLOGIN=iscLogin

# output dir for binaries and libs
OUTPUT=output

# profile
PROFILE=test

# rules
all: $(HTTP_GATEWAY) $(BACKEND) $(SCRIPTS) $(AUTOMATION) $(AI)

package: $(HTTP_GATEWAY) $(BACKEND) $(SCRIPTS) $(AUTOMATION) $(AI)
	@cp ai/test_configs/dataEnv/* output/dataEnv/bin/
	@tar czf output/heiyu.tar.gz output/{bin,lib,conf,dataEnv}
	@tar czf output/ai_training.tar.gz output/dataEnv output/bin/ai_training output/bin/training*


clean:
	@rm -rf output/bin/* output/lib/* output/fe/*

env:
	# source $(BUILD_ROOT)/env.sh
	@mkdir -p $(OUTPUT)/{bin,lib,conf,licenses}



$(POWER_AGENT):
	$(MAKE) -C power_agent
	
$(HTTP_GATEWAY): env
	$(MAKE) -C http-gateway

$(BACKEND): env
	$(MVN) clean package -DskipTests -P$(PROFILE)

$(POWER_MASTER): env
	$(MVN) clean package -pl powermaster/powermaster-server -am -DskipTests -P$(PROFILE)

$(POWER_MARKET): env
	$(MVN) clean package -pl market/market-server -am -DskipTests -P$(PROFILE)

$(POWER_MARKET_ADAPTER): env
	$(MVN) clean package -pl market/market-client-adapter -am -DskipTests -P$(PROFILE)

$(I6000): env
	$(MVN) clean package -pl i6000 -am -DskipTests -P$(PROFILE)

$(AUTOMATION): env
	$(MAKE) -C testing

$(SVC_ISCLOGIN): env
	$(MVN) clean package -pl iscLogin -am -DskipTests -P$(PROFILE)

$(AI): env
	$(MAKE) -C ai P=$(PROFILE)

$(SCRIPTS): env
	@cp -r scripts/* $(OUTPUT)/bin
	@cp -r scripts/*.xml $(OUTPUT)/conf
	@cp -r licenses/LICENSE.* $(OUTPUT)/licenses


.PHONY : all clean env
